package zjh_20230327;

import kfm.model.CateGory;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;


public class DBUtilsDemo {

    public static void main(String[] args) throws SQLException {
        String url = "jdbc:mysql://localhost:3306/store";
        String username = "root";
        String password = "";
        DBUtils<Category> dbUtils = new DBUtils<>(url, username, password);

        String sql = "SELECT * FROM category where no = ?";
        Category category = new Category();
        dbUtils.Select(sql, new Recover<Category>() {

            @Override
            public Category recover(ResultSet resultSet) {

                try {
                    category.setNo(resultSet.getInt("no"));
                    category.setName(resultSet.getString("name"));
                } catch (SQLException e) {
                    throw new RuntimeException(e);
                }
                return category;
            }
        }, 1);
        System.out.println(category);
    }

}
